﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace intelliEssayHelpAgent
{
    public class HelpAndSupportItem
    {
        public string URI { get; set; }
        public string Topic;
        public HelpAndSupportItem(string uri, string topic)
        {
            URI = uri;
            Topic = topic;
        }
        public override string ToString()
        {
            return Topic;
        }
    }
    public class HelpAndSupportItemCollection
    {
        private static HelpAndSupportItemCollection _helpCollection;
        static HelpAndSupportItemCollection()
        {
            // initialize collection here
            _helpCollection = new HelpAndSupportItemCollection();
            string[] helpPaths =
            Directory.GetFiles(Directory.GetCurrentDirectory() + "\\help", "*.rtf");
            _helpCollection.helpItems = new HelpAndSupportItem[helpPaths.Length];
            for (int i = 0; i <= _helpCollection.helpItems.Length - 1; i++)
            {
                string topic = helpPaths[i].Substring(helpPaths[i].LastIndexOf('\\') + 1, helpPaths[i].Length - helpPaths[i].LastIndexOf('\\') - 1);
                _helpCollection.helpItems[i] = new HelpAndSupportItem(helpPaths[i], topic);
            }
        }
        private HelpAndSupportItemCollection()
        { }
        public static HelpAndSupportItemCollection GetCurrentHelpCollection()
        {
            return _helpCollection;
        }
        /// <summary>
        /// Gets the required uri that corresponds to the required topic.
        /// </summary>
        /// <param name="key">keywords or topic</param>
        /// <returns>returns the uri of the topic</returns>
        public IEnumerable<HelpAndSupportItem> this[string key]
        {
            get
            {
                key = key.ToLowerInvariant();
                IEnumerable<HelpAndSupportItem> items = from helpItem
                                                            in helpItems
                                                        where helpItem.Topic.ToLowerInvariant().Contains(key)
                                                        select helpItem;
                return items;

            }
        }
        HelpAndSupportItem[] helpItems;
    }
}
